<?php
    use User\Model\CardModel;
?>
<!-- page heading start-->
<div class="page-heading">
    <h3>
        卡片
    </h3>

</div>
<!-- page heading end-->
<div class="row">
    <div class="col-sm-12">
        <section class="panel">
            <header class="panel-heading">
                <a class="btn btn-default" href="/User/Card/add">增加</a>
            </header>
            <div class="panel-body">
                <table class="table table-hover general-table table-bordered">
                    <thead>
                    <tr>
                        <th width="12%">卡片名称</th>
                        <th width="10%">状态</th>
                        <th width="12%">添加时间</th>
                        <th width="12%">起始时间</th>
                        <th width="12%">结束时间</th>
                        <th width="12%">路径</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <?php foreach($list as $val){?>
                    <tr>
                        <td>
                            <span>
                                <?php echo $val['name'];?>
                            </span>
                        </td>
                        <td>
                            <span>
                                <?php echo CardModel::get_status($val['status']);?>
                            </span>
                        </td>
                        <td>
                            <span>
                                <?php echo $val['added_date'];?>
                            </span>
                        </td>
                        <td>
                            <span>
                                <?php echo $val['start_date'];?>
                            </span>
                        </td>
                        <td>
                            <span>
                                <?php echo $val['end_date'];?>
                            </span>
                        </td>
                        <td>
                            <span>
                                <?php echo $_SERVER['SERVER_NAME'] . '/Wap/Card/index?id=' . $val['card_id'];?>
                            </span>
                        </td>
                        <td>
                            <div>
                                <a class="btn btn-default"
                                   href="<?php echo '/User/Card/update?type=update&cardId=' . $val['card_id'];?>">编辑</a>
                                <a class="btn btn-danger" href="#"
                                   onclick="<?php echo 'return delete_data(' . $val['card_id'] .')';?>">删除</a>
                                <a class="btn btn-success" href="#"
                                   onclick="<?php echo 'return pass_data(' . $val['card_id'] .')';?>">发布</a>
                                <a class="btn btn-warning" href="#"
                                   onclick="<?php echo 'return unpass_data(' . $val['card_id'] .')';?>">停用</a>
                            </div>
                            <div style="margin-top: 10px;">
                                <a class="btn btn-info"
                                   href="<?php echo '/User/Card/register?cardId=' . $val['card_id'];?>">用户</a>
                                <a class="btn btn-info"
                                   href="<?php echo '/User/Card/share?id=' . $val['card_id'];?>">分享设置</a>
                            </div>
                        </td>
                    </tr>
                    <?php }?>

                    </tbody>
                </table>
                <div class="pages">
                    {$page}
                </div>
            </div>
        </section>
    </div>
</div>
<script>
    function delete_data(id){
        $.ajax({
            data:{cardId:id},
            dataType:'json',
            url:'/User/Card/delete',
            type:'get',
            success:function(res){
                window.location.reload();
            }
        });
        return false;
    }
    function pass_data(id){
        $.ajax({
            data:{cardId:id},
            dataType:'json',
            url:'/User/Card/pass',
            type:'get',
            success:function(res){
                window.location.reload();
            }
        });
        return false;
    }
    function unpass_data(id){
        $.ajax({
            data:{cardId:id},
            dataType:'json',
            url:'/User/Card/unpass',
            type:'get',
            success:function(res){
                window.location.reload();
            }
        });
        return false;
    }
</script>